# (setq py-indent-offset 2)
from java.lang import *
from it.unimi.dsi.law.rank import *
from it.unimi.dsi.law.stat import *
from StringIO import *

class RankerTask(Runnable):
  def __init__(self, graph, alpha,
			   iterations, barrier):
	pagerank = PageRank(graph)
	pagerank.alpha = alpha
	pagerank.init()
	self.graph = graph
	self.alpha = alpha
	self.iterations = iterations
	self.barrier = barrier
	self.logger = StringIO('')
	self.pagerank = pagerank
  def run(self):
	print >> self.logger,\
		  '[nodes = %d, links = %d]' % \
		  (self.graph.n, self.graph.m)
	for i in range(self.iterations):
	  self.pagerank.step()
	  if i > 0:
		tau = KendallTau.compute(
		  self.pagerank.rank,
		  self.pagerank.previousRank)
		print >> self.logger,\
			  '[iter = %d, tau = %f]' % \
			  (i + 1, tau)
	self.barrier.await()
	
